package com.tianji.learning.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tianji.learning.domain.po.PointsBoard;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.mapper.PointsBoardSeasonMapper;
import com.tianji.learning.service.PointsBoardSeasonService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Optional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 */
@Service
public class PointsBoardSeasonServiceImpl extends ServiceImpl<PointsBoardSeasonMapper, PointsBoardSeason> implements PointsBoardSeasonService {


        /**
     * 根据上月时间查询对应的赛季 ID
     *
     * @param time 用于查询赛季 ID 的时间，通常为上月的时间
     * @return 返回查询到的赛季 ID，如果未找到则返回 null
     */
    @Override
    public Integer querySeasonByTime(LocalDateTime time) {
        // 使用 Lambda 查询构造器，筛选出开始时间小于等于指定时间且结束时间大于等于指定时间的赛季记录
        Optional<PointsBoardSeason> optional = lambdaQuery()
                .le(PointsBoardSeason::getBeginTime, time)
                .ge(PointsBoardSeason::getEndTime, time)
                .oneOpt();
        // 如果存在符合条件的赛季记录，则返回其 ID；否则返回 null
        return optional.map(PointsBoardSeason::getId).orElse(null);
    }

}
